/*
* @Author: Administrator
* @Date:   2017-12-22 14:27:05
* @Last Modified by:   Administrator
* @Last Modified time: 2018-01-03 13:12:17
*/
const express = require('express')
const path = require('path');
const fs = require('fs');
const serverEntry = require('../../dist/server/server_entry.js')
const serverRender = require('./server_render.js')
const serverDist = function (app) {
  app.use('/dist',express.static(path.join(__dirname,'../../dist')))
  app.get('*', function(req,res,next){
    const bundleModule = serverEntry;
    const template = fs.readFileSync(path.join(__dirname,'../../dist/index.ejs'),'utf-8')
    serverRender(bundleModule, template, req, res).catch(next)
  })
}
module.exports = serverDist;
